package com.wanaofu.utils;

import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.bridge.MessageUtil;

import com.wanaofu.MessageHandler;

public class FacesUtils {
    private static final Log log = LogFactory.getLog(MessageUtil.class);
    private static final String DEFAULT_BUNDLE = "javax.faces.Messages";
    
    public static String getRequestParameter(String name) {
        return getRequestParameter(FacesContext.getCurrentInstance(), name);
    }
    
    public static String getRequestParameter(FacesContext facesContext, String name) {
    	Map<String, String> params = facesContext.getExternalContext().getRequestParameterMap();
    	if (params != null) {
    		System.out.println("============params not null=============" );
    		for (String k: params.keySet()) {
    			System.out.println("============params not null=============" + k);
    			if (k.indexOf(name) != -1) {
    				System.out.println("============find key:" + k + " value:" + params.get(k));
    	            return params.get(k); // This is Your input parameter value waiting to be processed ;)
    			}   
    	    }
    	}
        return null;
    }
	
    public static void setMessage(String meg) {
    	FacesContext context = FacesContext.getCurrentInstance();  
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Successful", meg));    	
    }
  
    public static void saveRedirectMessage(String meg) {
    	FacesContext context = FacesContext.getCurrentInstance();  
        context.addMessage(MessageHandler.redirectToken_client_id, new FacesMessage(FacesMessage.SEVERITY_INFO, "Successful", meg));    	
    }
    
}
